Forbid unused property renaming in destructuring binding in function types#41044
Conversation
|
@rbuckton this may be affected when you change the way binding patterns are handled. |
Note that this PR is a breaking change, so can’t be merged into 4.1—it means people consuming existing declarations generated from totally reasonable code (your |
|
Perhaps a gentler way of doing this is putting it under |
|
Happy hacktoberfest again! 🎃🥳 @andrewbranch cc: @rbuckton I would like to request your re-check. Thank you. |
|
Wow, this PR really came back from the dead! 🧟 |
|
Still technically a breaking change, so let’s look in the 4.6 timeline. Thanks! |
|
@andrewbranch your last comment makes it sound like this is ready to be merged, but early in a release cycle. Is that true? Am I misreading it? |
andrewbranch
left a comment
There was a problem hiding this comment.
I definitely think we should get this into 4.8 because having forgotten what it was about and returning to the test, I totally fell for the trick that this tries to prevent, thinking string in ({ a: string }) => any is a type annotation 😆
I think it may be worth bringing a couple things to a design meeting:
- Should this error be triggered by
noUnusedLocals,noUnusedParameters, or neither? I know previously I had suggested it might make sense for it to be behind a flag, and I think you could bikeshed whether a rebinding of a destructured parameter is a parameter or a local. But looking at it now, there is truly no reason to write this syntax, so I think it may be worth considering always making it an error. On the other hand, bothnoUnusedoptions have pretty wide adoption, so maybe it’s fine as it is. - Especially if we decide to always make it an error, do we want a specialized message for this? When I looked at the error baseline for the first time in a year, I was briefly confused. It’s normal for names declared in types to be “never read,” and the message really sounds cryptic if you were under the impression that
: stringwas a type annotation. I think a better error message would indicate what the syntax is: “Rebinding a destructured parameter is not allowed in a function type” or something (needs some work). - I’m still concerned about new errors popping up in declaration files that we generated from existing code. I’m second-guessing my previous feedback that we shouldn’t change declaration emit to avoid this pattern, and I also want to think about whether we can/should suppress this check in declaration files.
| type F2 = ({ a: string }) => any; | ||
| ~~~~~~~~~~~~~ | ||
| !!! error TS6133: 'string' is declared but its value is never read. |
There was a problem hiding this comment.
Looking at the error span on this, it feels a bit odd for it to be the whole binding pattern rather than just the element or just string. It would be good to add a test like
type F2 = ({ a: string, b }) => any;which I think will really indicate whether the error span is appropriate.
|
Decision from design meeting:
|
|
@uhyo are you interested in making these changes, almost 2 years later? 😆 |
|
Sure! I'll work on this within a few days. |
|
I think #50483 is probably cause by this PR, could anyone check it? |
Happy hacktoberfest!! 🎃🥳
Fixes #37454.
The PR implements mainly two things, as suggested in #41044 (comment):
noUnusedLocalsnornoUnusedParameters, but declaration files are not checked.Example
Results
All the errors below are new in this PR.